export default class Loading {

  private _value: boolean = false;

  private count: number = 0;

  public get value() {
    return this._value;
  }

  private open() {
    this._value = true;
    this.count++;
  }

  private close() {
    this.count--;
    if (this.count === 0) {
      this._value = false;
    }
  }

  public async execute(func: () => Promise<void>) {
    this.open();
    try {
      await func();
    } finally {
      this.close();
    }
  }

}
